import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
import './assets/css/global.css'
//导入axios
import axios from "axios";
import './plugins/ant-design-vue.js'
// 导入语言包
import i18n from '../public/languages/i18n'
import {MessageBox} from 'element-ui'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import echarts from 'echarts'
import VueParticles from 'vue-particles'


Vue.use(VueParticles)
NProgress.configure({
  easing: 'ease',  // 动画方式
  speed: 500,  // 递增进度条的速度
  showSpinner: false, // 是否显示加载ico
  trickleSpeed: 200, // 自动递增间隔
  minimum: 0.3 // 初始化时的最小百分比
})
axios.interceptors.request.use(

    config => {

      if(window.sessionStorage.getItem("token")){
        config.headers.Authorization = window.sessionStorage.getItem("token")
      }else {
        config.headers.Authorization = 'null'
      }


      return config
    },
    error => {
      return Promise.error(error)
    },
    NProgress.start(),
)
axios.interceptors.response.use(
    NProgress.done()
)


Vue.directive('title', {
    inserted: function (el, binding) {
        document.title = el.dataset.title
    }
})




router.beforeEach((to, from, next) => {
  NProgress.start()
  if(to.path=='/Index')return next ()
  if(to.path=='/getEmail') return next()
  if(to.path=='/changePasword') return next()
  const userFlag = window.sessionStorage.getItem("user")
  if(!userFlag) return next('Index');
  next();
})

router.afterEach(() => {
  NProgress.done()
})
Vue.use(Antd);
Vue.prototype.$echarts = echarts
Vue.prototype.$confirm=MessageBox.confirm;

//挂载
Vue.prototype.$http = axios
//设置访问根路径
axios.defaults.baseURL = "http://localhost:9000/store"
Vue.config.productionTip = false

new Vue({
  router,
  i18n,
  render: h => h(App)
}).$mount('#app')
